package com.neu.controller;

import com.neu.dto.ProductDTO;
import com.neu.service.ProductService;
import com.neu.utils.ResultModel;
import com.neu.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    ProductService productService;


    @GetMapping
    public ResultModel<List<ProductVO>> find(ProductDTO productDTO){
        List<ProductVO> productVOList = productService.find(productDTO);
        ResultModel<List<ProductVO>> resultModel = new ResultModel<>();

        resultModel.setMsg("查询成功");
        resultModel.setData(productVOList);
        return resultModel;
    }

    @GetMapping("/getProductInfo/{shopId}")
    public ResultModel<List<ProductVO>> getProductInfo(@PathVariable("shopId") Integer shopId){
        List<ProductVO> productVOList = productService.selectByShopId(shopId);
        ResultModel<List<ProductVO>> resultModel = new ResultModel<>();

        resultModel.setMsg("查询成功");
        resultModel.setData(productVOList);
        return resultModel;
    }

    @PutMapping
    public ResultModel add(ProductDTO productDTO){
        ResultModel resultModel = new ResultModel();
        int count = productService.add(productDTO);
        resultModel.setMsg("添加商品成功");
        resultModel.setTotal(count);
        return resultModel;
    }

    @DeleteMapping
    public ResultModel delete(ProductDTO productDTO){
        ResultModel resultModel = new ResultModel();
        int count = productService.delete(productDTO);
        resultModel.setMsg("删除商品成功");
        resultModel.setTotal(count);
        return resultModel;
    }
 }
